//
// Created by mi on 2025/3/16.
//
#include <iostream>
#include <memory_resource>
#include <vector>
#include <memory.h>

int main() {
    // 配置内存池选项
    std::pmr::pool_options options;
    options.max_blocks_per_chunk = 1024;
    options.largest_required_pool_block = 64;

    // 创建内存池
    std::pmr::unsynchronized_pool_resource pool(options);

    // 使用内存池分配内存
    int* p1 = static_cast<int*>(pool.allocate(sizeof(int)));
    *p1 = 42;
    std::cout << "p1: " << *p1 << std::endl;

    // 使用内存池释放内存
    pool.deallocate(p1, sizeof(int));

    // 使用内存池与标准容器结合
    std::pmr::vector<int> vec{&pool};
    for (int i = 0; i < 10; ++i) {
        vec.push_back(i);
    }

    for (int val : vec) {
        std::cout << val << " ";
    }
    std::cout << std::endl;

    return 0;
}